#include <bits/stdc++.h>

#define ll long long
#define ull unsigned long long
#define uint unsigned int

#define YES cout << "Yes" << '\n'
#define NO cout << "No" << '\n'
#define endl '\n'
const int INF = 1e9;
const int MOD = 1;
using namespace std;
/*思考
 *n方拿下
 */

void solve()
{
    string s;
    cin >> s;
    int year = 0;
    year = (s[0] - '0') * 1000 + (s[1] - '0') * 100 + (s[2] - '0') * 10 + (s[3] - '0');
    for (int i = 0; i < 100; i++) {
        for (int j = 0; j < 100; j++) {
            if ((i + j) * (i + j) == year) {
                cout << i << ' ' << j << endl;
                return;
            }
        }
    }
    cout << -1 << endl;
}

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    int t = 0;
    cin >> t;
    while (t--)
        solve();
    return 0;
}